﻿using System;
using System.Collections.Generic;
using System.Linq;
using Gp.Scripts.Data.Skills;

namespace Gp.Scripts.Core {
    [Serializable]
    public struct ResourceCost {
        public CostField Type;
        public int Amount;

        public ResourceCost(CostField type, int amount = 1) {
            Type = type;
            Amount = Math.Max(amount, 0);
        }
    }

    public class CostWrapper {
        /// <summary>
        /// 代表使用所有资源
        /// </summary>
        public readonly bool AllResource;
        public static readonly CostWrapper Empty = All();
        public List<ResourceCost> Costs;

        private CostWrapper(IEnumerable<ResourceCost> costs, bool allResource = true) {
            AllResource = allResource;
            Costs = new List<ResourceCost>(costs);
        }


        public static CostWrapper Any(params ResourceCost[] cost) {
            return new CostWrapper(cost, false);
        }
        
        public static CostWrapper Any(IEnumerable<ResourceCost> cost) {
            return new CostWrapper(cost, false);
        }

        public static CostWrapper Any(params CostField[] types) {
            return new CostWrapper(types.Select(t => new ResourceCost(t)), false);
        }

        public static CostWrapper All(params ResourceCost[] cost) {
            return new CostWrapper(cost, true);
        }

        public static CostWrapper All(IEnumerable<ResourceCost> cost) {
            return new CostWrapper(cost, true);
        }
    }


}